#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maximumDifference(vector<int>& nums) {
        int res = 0;
        int mmin = nums[0];
        for (int i = 1; i < nums.size(); i++)
        {
            res = max(res, nums[i] - mmin);
            mmin = min(mmin, nums[i]);
        }
        return res == 0 ? -1 : res;
    }
};